<template>
  <div>
    <div class="fl">
      <div>
        <p class="title">评论列表</p>
        <span class="zt">状态:</span>
        <el-select
          v-model="value"
          placeholder="请选择"
          size="small"
          class="ztxz"
        >
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </div>

      <div >
        <div  class="search">
          <div class="el-icon-search"></div>
          <el-input
            class="seainput "
            type="text"
            placeholder="搜索用户/动态标题"
            v-model="input"
          @keyup.enter.native="search" @blur="search"
          />
        </div>
      </div>
    </div>

    <el-button type="primary" size="small" class="add">不通过</el-button>
    <el-button type="primary" size="small" class="add">通过</el-button>
    <!-- 表格 -->
    <el-table
      ref="multipleTable"
      :data="tableData"
      tooltip-effect="dark"
      style="width: 100%"
      border
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center">
      </el-table-column>
      <el-table-column label="序号" width="120" type="index" align="center">
        <!-- <template slot-scope="scope">{{ scope.row.date }}</template> -->
      </el-table-column>
      <el-table-column
        prop="account"
        label="用户账号"
        width="120"
        align="center"
      >
      </el-table-column>
      <el-table-column
        prop="grade"
        label="评论类型"
        show-overflow-tooltip
        align="center"
      >
      </el-table-column>
      <el-table-column
        prop="content"
        label="评论内容"
        align="center"
        show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column
        prop="superiorAccount"
        label="上级评论账号"
        align="center"
        show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column
        prop="superiorContent"
        label="上级评论内容"
        align="center"
        show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column
        prop="comTime"
        label="评论时间"
        show-overflow-tooltip
        align="center"
      >
      </el-table-column>
      <el-table-column
        prop="state"
        label="状态"
        show-overflow-tooltip
        align="center"
      >
      </el-table-column>
      <el-table-column
        prop="deleteTime"
        label="删除时间"
        show-overflow-tooltip
        align="center"
      >
      </el-table-column>
      <el-table-column
        prop=""
        label="操作"
        show-overflow-tooltip
        align="center"
        width="120"
      >
        <template slot-scope="scope">
          <el-link type="primary" @click="tongguo(scope.row)">通过</el-link>
          <el-link type="primary">不通过</el-link>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <Page
      :total="total"
      :pageNumber.sync="pageNumber"
      :pageSize.sync="pageSize"
      @current-change="changeCurrentPage"
      @size-change="handleSizeChange"
    >
    </Page>
  </div>
</template>

<script>
import Page from "../../components/page.vue";
import apis from "../../apis/modules/commentList";
export default {
  components: {
    Page,
  },
  data() {
    return {
      input: "",
      // 分页默认值
      currentPage: 1,
      pageNumber: 1,
      pageSize: 10,
      total: null,
      //搜索
      input: "",
      options: [
        {
          value: "all",
          label: "全部",
        },
        {
          value: "1",
          label: "已上架",
        },
        {
          value: "2",
          label: "已下架",
        },
      ],
      value: "all",
      tableData: [],
    };
  },
  mounted() {
    this.getComment({
      state: this.value,
      pageNumber: this.pageNumber,
      pageSize: this.pageSize,
    });
  },
  watch: {
    value() {
      switch (this.value) {
        case "all":
          this.getComment({
            state: this.value,
            pageNumber: this.pageNumber,
            pageSize: this.pageSize,
          });
          break;
        case "1":
          this.getComment({
            state: this.value,
            pageNumber: this.pageNumber,
            pageSize: this.pageSize,
          });
          break;
        case "2":
          this.getComment({
            state: this.value,
            pageNumber: this.pageNumber,
            pageSize: this.pageSize,
          });
          break;

        default:
          break;
      }
    },
  },
  methods: {
    //通过
    tongguo(){

    },
    //搜索
    search() {
      const txt = {
        state: this.value,
        pageNumber: this.pageNumber,
        pageSize: this.pageSize,
        content: this.input,
      };
      this.getComment(txt);
      this.input = "";
    },
    //获取评论列表
    async getComment(data) {
      await apis.getComment(data).then((res) => {
        console.log(res, "res");
        if ((res.code = 200)) {
          this.total = res.data.count;
          this.tableData = res.data.list;
          const list = this.tableData;
          list.map((res) => {
            res.grade = `${res.grade}级`;
            switch (res.state) {
              case "1":
                res.state = "上架";
                break;
              case "2":
                res.state = "下架架";
                break;

              default:
                break;
            }
            return res;
          });
        }
      });
    },
    toggleSelection(rows) {
      if (rows) {
        rows.forEach((row) => {
          this.$refs.multipleTable.toggleRowSelection(row);
        });
      } else {
        this.$refs.multipleTable.clearSelection();
      }
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    //分页
    //当前页
    changeCurrentPage(val) {
      this.pageNumber = val;
      const list = {
        state: this.value,

        pageNumber: this.pageNumber,
        pageSize: this.pageSize,
      };
      this.getComment(list);
      console.log(val, 333);
    },
    //改变每页显示条数
    handleSizeChange(val) {
      this.pageSize = val;
      const list = {
        state: this.value,
        pageNumber: this.pageNumber,
        pageSize: this.pageSize,
      };

      this.getComment(list);
      console.log(val, 222);
    },
  },
};
</script>

<style lang="scss" scoped>
.title {
  margin-top: -10px;
  font-size: 14px;
  margin-bottom: 40px;
}
.zt {
  margin: 40px 10px 20px 20px;
}
.el-input--small .el-input__inner {
  height: 32px;
  line-height: 32px;
  width: 126px;
}
.add {
  width: 88px;
  float: right;
  margin-top: 40px;
  margin-left: 20px;
}
.el-link {
  display: inline-block;
  width: 50px;
  text-align: center;
}
.search {
 /deep/.el-input__inner {
    -webkit-appearance: none;
    background-color: #DCDFE6;
    background-image: none;
    border-radius: 8px;
    border: 1px solid #DCDFE6;
    box-sizing: border-box;
    color: #606266;
    display: inline-block;
    font-size: inherit;
    height: 40px;
    line-height: 40px;
    outline: 0;
    padding: 0 15px;
    transition: border-color .2s cubic-bezier(.645,.045,.355,1);
    width: 100%;
}
  height: 40px;
  background: #DCDFE6;
  margin-top: 30px;
  display: flex;
      border-radius: 8px;
  .el-icon-search{
    line-height: 40px;
    height: 40px;
  }
 
}
 
.fl {
  display: flex;
  justify-content: space-between;
}
</style>